package cn.gcBlock.rest;

import cn.gcBlock.service.DigOreService;
import cn.gcBlock.po.DigOre;
import cn.gcBlock.dto.DigOreQueryCriteria;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @author jie
 * @date 2019-09-15
 */
@Api(tags = "DigOre管理")
@RestController
@RequestMapping("api")
public class DigOreController {

    @Autowired
    private DigOreService digOreService;

    @ApiOperation(value = "查询DigOre")
    @GetMapping(value = "/digOre")
    public ResponseEntity getDigOres(DigOreQueryCriteria criteria, Pageable pageable) {
        return new ResponseEntity(digOreService.queryAll(criteria, pageable), HttpStatus.OK);
    }

    @ApiOperation(value = "新增DigOre")
    @PostMapping(value = "/digOre")
    public ResponseEntity create(@Validated @RequestBody DigOre resources) {
        return new ResponseEntity(digOreService.create(resources), HttpStatus.CREATED);
    }
    @ApiOperation(value = "修改DigOre")
    @PutMapping(value = "/digOre")
    public ResponseEntity update(@Validated @RequestBody DigOre resources) {
        digOreService.update(resources);
        return new ResponseEntity(HttpStatus.NO_CONTENT);
    }
    @ApiOperation(value = "删除DigOre")
    @DeleteMapping(value = "/digOre/{id}")
    public ResponseEntity delete(@PathVariable Integer id) {
        digOreService.delete(id);
        return new ResponseEntity(HttpStatus.OK);
    }
}